<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');

function cleanFilesNotUsed($user_id){
/**	$ci=& get_instance();
	$user_show = $ci->db->where('user_created_id',$user_id)->get(TBL_SHOW)->result();
	$USER = $ci->user_entity->init('id',$user_id);
	
	$file_using_array = array();
	foreach($user_show as $show){
		$showOBJ = $ci->show_entity->init('id',$show->id);
		$file_using_array[] = $showOBJ->getTechRider();
		$file_using_array[] = $showOBJ->getShowImage1();
		$file_using_array[] = $showOBJ->getShowImage2();
		$file_using_array[] = $showOBJ->getShowImage3();
		$file_using_array[] = $showOBJ->getHospitalityRider();
		
		$revision_array = unserialize($showOBJ->getRevision());
		if(!empty($revision_array)){
			foreach($revision_array as $revision){
				$file_using_array[] = $revision['tech_rider'];
				$file_using_array[] = $revision['show_image_1'];
				$file_using_array[] = $revision['show_image_2'];
				$file_using_array[] = $revision['show_image_3'];
				$file_using_array[] = $revision['hospitality_rider'];
			}
		}
	}
	
	if ($handle = opendir($USER->getFolderFileStorage())) {
		while (false !== ($file = readdir($handle))) {
			if(!in_array($file, $file_using_array) AND $file !='.' AND $file != '..' AND $file != 'index.php' AND $file != 'index.html'){
		        @unlink($USER->getFolderFileStorage().$file);
		    }
		}
		closedir($handle);
	}
**/	
}

function countNumberUserOfStatus($user_status='pending', $user_type='seller'){
	$ci=& get_instance();
	$number = count($ci->db->where(array('status'=>$user_status, 'acc_type'=>$user_type))->get(TBL_ACCOUNT)->result());
	return $number;
}

function countNumberShowOfStatus($show_status= 'opening'){
	$ci=& get_instance();
	return count($ci->db->where(array('status'=>$show_status))->get(TBL_SHOW)->result());
}

function countBidOfStatus($bid_status = 'bidding'){
	$ci=& get_instance();
	switch($bid_status){
		case 'bidding':
		default:
			$count = count(
						$ci->db->select("TBLBID.*")->
						from(TBL_BID." AS TBLBID")->
						join(TBL_SHOW." AS TBLSHOW","TBLBID.show_ref_no=TBLSHOW.ref_no")->
						where("TBLSHOW.status",'opening')->
						get()->result() 
					);
			break;
		case 'processing':	
			$count = count(
						$ci->db->
						where( "status LIKE 'closed' AND pay_status IS NULL AND user_bid_won IS NOT NULL" )->
						get(TBL_SHOW)->result() 
					);
			break;
		case 'completed':
			$count = count(
						$ci->db->
						where( "status LIKE 'closed' AND pay_status IS NOT NULL AND user_bid_won IS NOT NULL")->
						get(TBL_SHOW)->result() 
					);
			break;
	}
	return $count;
}